Disallow nesting of packages with same packge_id
authorSeth Falcon <seth@chef.io>
Fri, 3 Jul 2015 22:36:25 +0000 (15:36 -0700)
committerSeth Falcon <seth@chef.io>
Fri, 3 Jul 2015 22:36:25 +0000 (15:36 -0700)
If a package contains a subdirectory that contains a copy of
itself (strange, but encountered in the wild in the context of an OS
package build tool), cargo was failing with a non-descriptive "An
unknown error occurred" (or "no package found in source" with
--verbose).

Since nested packages use the root path, such a package will have an
identical package_id to the root package. With this patch, we keep the
first occurance of a given package_id rather than overwritting --
effectively ignoring the nested package with duplicated name. A warn!
message is printed.

src/cargo/ops/cargo_read_manifest.rs

index 85078532671c46113543906949fd39e562f08500..3711d263eeb796423608e6e4ac8fd7ae5a9a38c8 100644 (file)
@@ -112,7 +112,13 @@ fn read_nested_packages(path: &Path,
     let manifest = try!(find_project_manifest_exact(path, "Cargo.toml"));
 
     let (pkg, nested) = try!(read_package(&manifest, source_id, config));
-    all_packages.insert(pkg.package_id().clone(), pkg);
+    let pkg_id = pkg.package_id().clone();
+    if !all_packages.contains_key(&pkg_id) {
+        all_packages.insert(pkg_id, pkg);
+    } else {
+        warn!("skipping nested package `{}` found at `{}`",
+              &pkg.name(), &path.to_string_lossy());
+    }
 
     // Registry sources are not allowed to have `path=` dependencies because
     // they're all translated to actual registry dependencies.